/**
 * Created by jf on 16/1/20.
 */

/**
 * Created by jf on 16/1/20.
 */
object IrcExpand {

  val timeP = "((\\[\\d{2}:\\d{2}\\.\\d{2}\\])+?)+?".r
  val wordP = "([^\\[\\d{2}:\\d{2}\\.{2}\\]].*)".r

  def expand(lrc: Seq[String]): Seq[String] = {
    var expand = Seq[String]()
    lrc.foreach(s => {
      val times = timeP.findAllIn(s)
      val word = wordP.findFirstIn(s)
      if (times.isEmpty) {
        expand = expand :+ s
      } else {
        times.foreach(t => {
          expand = expand :+ (t + word.getOrElse(""))
        })
      }
    })

    expand = expand.sortWith((s1, s2) => {
      !timeP.findAllIn(s1).isEmpty && !timeP.findAllIn(s2).isEmpty && s1 < s2
    })

    expand
  }

}

